<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>用户注册</title>
		<link rel="stylesheet" type="text/css" href="./static/admin/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="./static/admin/css/login.css" />
		<script src="https://ssl.captcha.qq.com/TCaptcha.js"></script>
		<script src="http://pv.sohu.com/cityjson"></script>
	            
	    <script type="text/javascript" src="./static/js/jquery-1.12.4.js"></script>
	    <script type="text/javascript" src="./static/js/my.js"></script>
	</head>

	<body>
		<div class="m-login-bg">
			<div class="m-login">
				<h3>用户注册</h3>
				<div class="m-login-warp">
					<form class="layui-form">
						<div class="layui-form-item">
							<input type="text" id="email" name="email" required lay-verify="email" placeholder="邮箱" autocomplete="off" class="layui-input">
						</div>
						<div class="layui-form-item">
							<input type="password" id="password" name="password" required lay-verify="required" placeholder="密码" autocomplete="off" class="layui-input">
						</div>
						<div class="layui-form-item">
							<input type="password" name="password2" required lay-verify="required" placeholder="确认密码" autocomplete="off" class="layui-input">
						</div>
						<div class="layui-form-item">
							<input type="text" id="phone" name="phone" required lay-verify="phone" placeholder="手机号" autocomplete="off" class="layui-input">
						</div>
						<div class="layui-form-item">
							<input type="text" name="verity" required lay-verify="required" placeholder="验证码,点击验证" autocomplete="off"
								   class="layui-input" id="TencentCaptcha" data-appid="2001614463" data-cbfn="callback">
						</div>
						<div class="layui-form-item m-login-btn">
							<div class="layui-inline">
								<button class="layui-btn layui-btn-normal" lay-submit lay-filter="login">注册</button>
							</div>
							<div class="layui-inline">
								<button type="reset" class="layui-btn layui-btn-primary">取消</button>
							</div>
						</div>
						<div class="layui-form-item">
							已有账号？<a href="/login.html">点击登录</a>
						</div>
					</form>
				</div>
				<p class="copyright">Copyright 2019</p>
			</div>
		</div>
		<script src="./static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" src="./static/js/jquery-1.12.4.js"></script>

		<script>
			var dic = new Array();
			window.callback = function (res) {

				if (res.ret === 0) {
					$("#TencentCaptcha").val("验证通过");
					$("#TencentCaptcha").hide();
					dic = res;

				} else {
					alert("验证失败了");
				}
			};
			layui.use(['form', 'layedit', 'laydate'], function() {
				var form = layui.form(),
					layer = layui.layer;


				//自定义验证规则
				form.verify({
					title: function(value) {
						if(value.length < 5) {
							return '标题至少得5个字符啊';
						}
					},
					password: [/(.+){6,12}$/, '密码必须6到12位'],
					verity: [/(.+){6}$/, '验证码必须是6位'],
					
				});

				
				//监听提交
				form.on('submit(login)', function(d) {

					dic['UserIP'] = returnCitySN["cip"];
            		var dataj = {"verify":dic, "email":$("#email").val(),"password" : $("#password").val(),"phone" : $("#phone").val()};
					// layer.alert(JSON.stringify(d.field), {
					// 	title: '最终的提交信息'
					// })
		            $.ajax(
	                	{
		                    url:'/api/user/register?key=ef6c288e29f8490c8b5ec8d4ec2a',
		                    type:'POST',
		                    data:JSON.stringify(dataj),
		                    xhrFields: {
		                        withCredentials: true
		                    },
		                    success:function(obj) {
		                        if(obj.code == 20){
									alert(obj.msg);
		                            // $(location).attr('href', 'index.html');
		                            setTimeout("window.location.href='/login.html'",1000);
		                        }
		                        else {
		                        	alert(obj.msg);
		                            // $('#error_msg').text(obj.msg)
		                        }
		                    },
		                    error:function(obj) {
		                        alert('未知错误');
		                    }
	                	}
            		)
					return false;
				});
			});

		</script>

	</body>

</html>